package dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.List;

import org.apache.commons.dbutils.handlers.BeanListHandler;

import dao.ReserveDao;
import model.ReservemsgModel;
import util.C3p0Util;
import util.DBUtil;

public class ReserveDaoImpl implements ReserveDao {

	@Override
	public void addReserveMsg(ReservemsgModel reservemsg) throws Exception {
		Connection connection=DBUtil.getconnection();
		PreparedStatement ps = connection.prepareStatement("INSERT INTO reservemsg(hotelid,roomtype,staytime,roomqty,roomindex,allprice,r_people,peoplephone,peopleemail,username) VALUES(?,?,?,?,?,?,?,?,?,?)");
		ps.setInt(1, reservemsg.getHotelid());
		ps.setString(2, reservemsg.getRoomtype());
		ps.setInt(3, reservemsg.getStaytime());
		ps.setInt(4, reservemsg.getRoomqty());
		ps.setInt(5, reservemsg.getRoomindex());
		ps.setDouble(6, reservemsg.getAllprice());
		ps.setString(7, reservemsg.getR_people());
		ps.setString(8, reservemsg.getPeoplephone());
		ps.setString(9, reservemsg.getPeopleemail());
		ps.setString(10, reservemsg.getUsername());
		ps.executeUpdate();
		ps.close();
		connection.close();
	}

	@Override
	public List<ReservemsgModel> listAll() throws Exception {
		return C3p0Util.qr.query("select * from reservemsg",new BeanListHandler<ReservemsgModel>(ReservemsgModel.class));
	}
	
}
